package com.tjl.warehouse.exception;

import com.tjl.warehouse.common.ErrorCode;

/**
 * 抛异常工具类
 * @author Tang
 */
public class ThrowUtils {

    /**
     * 条件成立则抛异常
     *
     * @param condition 条件
     * @param runtimeException 异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 条件成立则抛异常
     *
     * @param condition
     * @param errorCode
     * @param message
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }

    public static void throwIfParams(boolean condition, String message) {
        throwIf(condition, new BusinessException(ErrorCode.PARAMS_ERROR, message));
    }
    public static void throwIfParams(boolean condition) {
        throwIf(condition, new BusinessException(ErrorCode.PARAMS_ERROR));
    }

    public static void paramsError(String msg) {
        throw new BusinessException(com.tjl.warehouse.common.ErrorCode.PARAMS_ERROR,msg);
    }
}
